package com.chen.demo.simple.handler;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.demo.simple.command.query.BookPageQuery;
import com.chen.demo.simple.domain.entity.Book;
import com.chen.demo.simple.repository.BookRepository;
import com.chen.winnerframework.cqrs.executor.CommandExecutor;
import com.chen.winnerframework.http.response.PageResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class BookPageQryExe implements CommandExecutor<BookPageQuery, PageResponse<Book>> {

    private final BookRepository bookRepository;

    @Override
    public PageResponse<Book> execute(BookPageQuery pageQuery) {
        Page<Book> bookPage = bookRepository.pageQueryBook(pageQuery);
        return PageResponse.success(bookPage);
    }
}
